var dangqian = '6';
var nowpage = 1

var form1 = {
    size: 10,
    page: 1,
    contacts: "",
    merchantNo: "",
    state: "",
    telephone: "",
    username: "",
}
var form2 = {
total: 2000,
pageSize: 10,
showTotal: true,
showTo: true,
change: function ( i ) {
    createContent( i );
}
}
var $content = $( ".content" );
function getTableData(form1){
    var form_showall = {
        contacts: form1.contacts,
        merchantNo: form1.merchantNo,
        state: form1.state,
        telephone: form1.telephone,
        username: form1.username,
    }
    $.ajax({
    url:initObj.url + "/api/user/findAllUser/" + form1.page + '/' + form1.size,
    data:JSON.stringify(form_showall),
    // data:form1,
    datatype:'json',
    type:'post',
    beforeSend: function(request) {
        request.setRequestHeader("token", form.token);
    //    console.log(form.token)
    },
    contentType: "application/json;charset=utf-8",
    success:function(res){
        console.log(res)
        document.getElementById('selectAll').innerHTML = ""
        for(var i=0;i<res.data.userDTO.length;i++){
            document.getElementById('selectAll').innerHTML += "<li><span style='display:inline-block;width:10vw'>"
            +res.data.userDTO[i].merchantNo+"</span><span style='display:inline-block;width:10vw'>"
            +res.data.userDTO[i].username+"</span><span style='display:inline-block;width:10vw'>"
            +res.data.userDTO[i].telephone+"</span><span style='display:inline-block;width:10vw'>"
            +res.data.userDTO[i].contacts+"</span><span class='state' style='display:inline-block;width:10vw'>"
            +res.data.userDTO[i].state+"</span><button style='color:#474c82;border:none;background-color:transparent' onclick='go_detail("+res.data.userDTO[i].id+")'>查看详情</button></li>"
            if(res.data.userDTO[i].state == '正常'){
                document.getElementsByClassName('state')[i].style.color = '#63c409'
            }else if(res.data.userDTO[i].state == '异常'){
                document.getElementsByClassName('state')[i].style.color = '#e0d42e'
            }else{
                document.getElementsByClassName('state')[i].style.color = '#f95959'
            }
        }
        if(form2.total !== res.data.tatol){
            form2.total = res.data.tatol
            Helper.ui.page("#page-3", form2);
            nowpage++
        }
    }
    })
}
// Helper.ui.page("#page-3", form2);
getTableData(form1)
function createContent (i) {
form1.page = i
getTableData(form1)
}
function changeinfo(id,value){
form1[id] = value
// console.log(form1)
}
function search(){
getTableData(form1)
}
function go_detail(id){
    console.log(id)
    sessionStorage.setItem('go_detail',id)
    window.location.href = 'shanghuxiangqin.html'
}


//新增用户

function create_user_show(){
    document.getElementById('create_user_show').style.display = 'block'
}
function create_user_close(){
    document.getElementById('create_user_show').style.display = 'none'
}
function create_user_OK(){
    var form_create = {
        password:hex_md5(password.value),
        poundage:poundage.value,
        rechargeRate:rechargeRate.value,
        overdraft:overdraft.value,
        substituteMoney:substituteMoney.value,
        bringForwardMoney:bringForwardMoney.value
    }   
    $.ajax({
        url:initObj.url + "/api/user/addMerchant/",
        data:JSON.stringify(form_create),
        // data:form1,
        datatype:'json',
        type:'post',
        beforeSend: function(request) {
            request.setRequestHeader("token", form.token);
        //    console.log(form.token)
        },
        contentType: "application/json;charset=utf-8",
        success:function(res){
            console.log(res)
            alert('新增成功,商户号为 : '+res.data.merchantNo+" 账号为 : "+res.data.username)
        }
    })
    create_user_close()
    getTableData(form1)
}